//  [10/17/2013 OMEGA] created

#ifndef _DUELECSELECTIONMODEL_H_
#define _DUELECSELECTIONMODEL_H_

#include <QSet>
#include <QList>
#include "DuelECCommon.h"
#include "Duel.h"
#include "DuelECSelectionMask.h"

namespace DuelEC
{

	class DUELEC_API DECSelectionModel
	{
	public:
		DECSelectionModel();
		virtual ~DECSelectionModel();

		typedef	QList<DECSelectable*>	SelectionList;
		typedef	std::list<DECSelectable*>	StdSelectionList;
		typedef	Duel::ListIterator<StdSelectionList>	SelectionIterator;
			//! Operations on selection lists
		enum ListAdjustment {
			LA_ReplaceList,   //!< Totally replace the list with the given items.
			/*! For each item, remove it to the list if that are
			  already present, add it otherwise.
			*/
			LA_XORWithList,   
			LA_AddToList,     //!< Add the items to the list.
			LA_RemoveFromList, //!< Remove the items from the list.
			LA_AddToHeadOfList //!< Add to beginning of the list.
		};
		

		void				setSelectionMask(DECSelectionMask mask);
		DECSelectionMask	getSelectionMask();

		// equals to mergeList(list, LA_ReplaceList);
		void				select(const SelectionList& list);

		// used for adding list. masks will apply to this list, too.
		void				mergeList(const SelectionList& list, ListAdjustment adjMethod);
		void				clearList();
		// notice that the selection iterator is not QIterator!
		SelectionIterator	getSelectionIterator()
		{
			mStdSelectionList = mSelectedObjs.toStdList();
			return SelectionIterator(mStdSelectionList.begin(), mStdSelectionList.end());
		}


	protected:
		void				filterListImpl(const SelectionList& list, SelectionList& outList);
		void				removeDuplicated(const SelectionList& list, SelectionList& outList);
		SelectionList		mSelectedObjs;
		StdSelectionList	mStdSelectionList;
		DECSelectionMask	mSelectionMask;
	};

}
// selection model is a class that manage the selection of objects.

#endif